package demo.bocweb.login_module.presenter;

import demo.bocweb.com.sdk.base.bean.BaseBean;
import demo.bocweb.com.sdk.baseApi.AppUrl;
import demo.bocweb.com.sdk.baseApi.BaseErrorObserver;
import demo.bocweb.com.sdk.baseApi.BaseObserver;
import demo.bocweb.com.sdk.util.Loading;
import demo.bocweb.com.sdk.util.ToastyUtil;
import demo.bocweb.login_module.contract.ResetPwdContract;
import demo.bocweb.login_module.model.ResetPwdModel;
import okhttp3.RequestBody;

/**
 * Created by zhelun on 2018/2/3.
 */

public class ResetPwdPresenter extends ResetPwdContract.IResetPwdPresenter {
    @Override
    public ResetPwdContract.IResetPwdModel getModel() {
        return ResetPwdModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void resetPwd(RequestBody body) {
        if (mIModel == null || mIView == null)
            return;
        mRxManager.register(mIModel.resetPwd(body)
                .subscribe(new BaseObserver<BaseBean>() {
                    @Override
                    public void setData(BaseBean baseBean) {
                        Loading.dismiss();
                        if (baseBean.getReturnCode() == AppUrl.SuccessCode) {
                            if (mIView == null)
                                return;
                            mIView.resetPwdSuccess();
                        } else {
                            ToastyUtil.showError(baseBean.getMsg());
                        }
                    }
                }, new BaseErrorObserver()));
    }
}
